package com.smag.web.controller.echarts.lineandbar;

import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.core.page.TableDataInfo;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.echarts.domain.EchartsLineBarSales;
import com.smag.echarts.service.EchartsLineBarSalesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController("lineAndBarSalesController")
@RequestMapping("/echarts/lineAndBar/sales")
public class SalesController extends BaseController {
    @Resource
    private EchartsLineBarSalesService echartsLineBarSalesService;
    @GetMapping("/listAll")
    public AjaxResult getSalesList(){
        return echartsLineBarSalesService.getSalesList();
    }

    /**
     * 查询农作物销售量与销售额列表
     */
    @PreAuthorize("@ss.hasPermi('system:sales:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsLineBarSales echartsLineBarSales)
    {
        startPage();
        List<EchartsLineBarSales> list = echartsLineBarSalesService.selectEchartsLineBarSalesList(echartsLineBarSales);
        return getDataTable(list);
    }

    /**
     * 导出农作物销售量与销售额列表
     */
    @PreAuthorize("@ss.hasPermi('system:sales:export')")
    @Log(title = "农作物销售量与销售额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsLineBarSales echartsLineBarSales)
    {
        List<EchartsLineBarSales> list = echartsLineBarSalesService.selectEchartsLineBarSalesList(echartsLineBarSales);
        ExcelUtil<EchartsLineBarSales> util = new ExcelUtil<EchartsLineBarSales>(EchartsLineBarSales.class);
        util.exportExcel(response, list, "农作物销售量与销售额数据");
    }

    /**
     * 获取农作物销售量与销售额详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sales:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return echartsLineBarSalesService.selectEchartsLineBarSalesById(id);
    }

    /**
     * 新增农作物销售量与销售额
     */
    @PreAuthorize("@ss.hasPermi('system:sales:add')")
    @Log(title = "农作物销售量与销售额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsLineBarSales echartsLineBarSales)
    {
        return echartsLineBarSalesService.insertEchartsLineBarSales(echartsLineBarSales);
    }

    /**
     * 修改农作物销售量与销售额
     */
    @PreAuthorize("@ss.hasPermi('system:sales:edit')")
    @Log(title = "农作物销售量与销售额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsLineBarSales echartsLineBarSales)
    {
        return echartsLineBarSalesService.updateEchartsLineBarSales(echartsLineBarSales);
    }

    /**
     * 删除农作物销售量与销售额
     */
    @PreAuthorize("@ss.hasPermi('system:sales:remove')")
    @Log(title = "农作物销售量与销售额", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return echartsLineBarSalesService.deleteEchartsLineBarSalesByIds(ids);
    }
}
